package com.itheima.ThreadPoolExecutor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolDemo {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,//核心线程数量
                5,//最大线程数
                2,//空闲线程最大存活时间
                TimeUnit.SECONDS,//空闲线程存活单位
                new ArrayBlockingQueue<>(10),//任务队列
                Executors.defaultThreadFactory(),//创建线程工厂
                //丢弃多余的任务并抛出异常
                new ThreadPoolExecutor.AbortPolicy());

        for (int i = 1; i <=16; i++) {
            pool.submit(()-> System.out.println(Thread.currentThread().getName()+"执行了任务"));
        }
        pool.shutdown();
    }
}
